const User = require('./User/User')
const UserInfo = require('./UserInfo/UserInfo')
const Menu = require('./Menu/Menu')
const Role = require('./Role/Role')
const UserAndRole = require('./UserAndRole/UserAndRole')
const Area = require('./Area/Area')
const School = require('./School/School')
const House = require('./House/House')
const Comment = require('./Comment/Comment')
const Reply = require('./Reply/Reply')
const Ask = require('./Ask/Ask')
const Lease = require('./Lease/Lease')

User.hasOne(UserInfo, {
  foreignKey: 'uid'
})

UserInfo.belongsTo(User, {
  foreignKey: 'uid'
})

User.hasOne(UserAndRole, {
  foreignKey: 'uid'
})

UserAndRole.belongsTo(User, {
  foreignKey: 'uid'
})

Role.hasMany(UserAndRole, {
  foreignKey: 'rid'
})

UserAndRole.belongsTo(Role, {
  foreignKey: 'rid'
})

Area.hasMany(House, {
  foreignKey: 'areaId'
})

House.belongsTo(Area, {
  foreignKey: 'areaId'
})

Area.hasMany(School, {
  foreignKey: 'areaId'
})

School.belongsTo(Area, {
  foreignKey: 'areaId'
})

School.hasMany(House, {
  foreignKey: 'schoolId'
})

House.belongsTo(School, {
  foreignKey: 'schoolId'
})

User.hasMany(House, {
  foreignKey: 'uid'
})

House.belongsTo(User, {
  foreignKey: 'uid',
  as: 'user'
})

House.belongsTo(User, {
  foreignKey: 'askId',
  as: 'askUser'
})

User.hasMany(Comment, {
  foreignKey: 'uid'
})

Comment.belongsTo(User, {
  foreignKey: 'uid'
})

House.hasMany(Comment, {
  foreignKey: 'houseId'
})

Comment.belongsTo(House, {
  foreignKey: 'houseId'
})

User.hasMany(Reply, {
  foreignKey: 'uid'
})

Reply.belongsTo(User, {
  foreignKey: 'uid'
})

Comment.hasMany(Reply, {
  foreignKey: 'contentId'
})

Reply.belongsTo(Comment, {
  foreignKey: 'contentId'
})

User.hasMany(Ask, {
  foreignKey: 'askId'
})

Ask.belongsTo(User, {
  foreignKey: 'askId'
})

House.hasMany(Ask, {
  foreignKey: 'houseId'
})

Ask.belongsTo(House, {
  foreignKey: 'houseId'
})

Ask.hasOne(Lease, {
  foreignKey: 'askId'
})

Lease.belongsTo(Ask, {
  foreignKey: 'askId'
})


module.exports = {
  User,
  UserInfo,
  Menu,
  Role,
  UserAndRole,
  Area,
  School,
  House,
  Comment,
  Reply,
  Ask,
  Lease
}
